﻿using System;
using CID.Execution.Support.Contracts;

namespace CID.Execution.Agent.Tests.Support
{
    class ControllerServiceProxyStub : IControllerService
    {
        public static bool NotifyDeactivationCompletedCalled { get; private set; }
        public static bool NotifyDeploymentCompletedCalled { get; private set; }
        public static bool NotifyActivationCompletedCalled { get; private set; }

        public static bool NotifyDeactivationCompletedWithErrors { get; private set; }
        public static bool NotifyDeploymentCompletedWithErrors { get; private set; }
        public static bool NotifyActivationCompletedWithErrors { get; set; }

        public static bool FailOnCall { get; set; }
        public const string FaillMessage = "Failing on purpose";

        static ControllerServiceProxyStub()
        {
            ClearFlags();
        }

        public static void ClearFlags()
        {
            NotifyDeactivationCompletedCalled = NotifyDeploymentCompletedCalled = NotifyActivationCompletedCalled = false;
            NotifyDeactivationCompletedWithErrors = NotifyDeploymentCompletedWithErrors = NotifyActivationCompletedWithErrors = false;
            FailOnCall = false;
        }

        public ControllerServiceProxyStub()
        {
            NotifyDeactivationCompletedCalled = NotifyDeploymentCompletedCalled = NotifyActivationCompletedCalled = false; 
        }

        public void NotifyDeactivationCompleted(Guid deploymentUniqueIdentifier, int locationId, string details, bool error)
        {
            if (FailOnCall) throw new Exception(FaillMessage);
            NotifyDeactivationCompletedCalled = true;
            NotifyDeactivationCompletedWithErrors = error;
        }

        public void NotifyDeploymentCompleted(Guid deploymentUniqueIdentifier, int locationId, string details, bool error)
        {
            if (FailOnCall) throw new Exception(FaillMessage);
            NotifyDeploymentCompletedCalled = true;
            NotifyDeploymentCompletedWithErrors = error;
        }

        public void NotifyActivationCompleted(Guid deploymentUniqueIdentifier, int locationId, string details, bool error)
        {
            if (FailOnCall) throw new Exception(FaillMessage);
            NotifyActivationCompletedCalled = true;
            NotifyActivationCompletedWithErrors = error;
        }

    }
}
